package com.marvin.spring.intercept.learning.config;

import com.marvin.spring.intercept.learning.interceptor.TimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @ClassName: WebIntercetorConfig
 * @Description: Interceptor 配置
 * @Author Marvin
 * @Date 2019/5/22 22:47
 */
@Configuration
public class WebInterceptorConfig extends WebMvcConfigurationSupport {
    //WebMvcConfigurerAdapter 在Springboot 2.0后过时了，以下WebMvcConfigurerAdapter 比较常用的重写接口
    ///** 添加拦截器 **/
    //void addInterceptors(InterceptorRegistry registry);
    ///** 解决跨域问题 **/
    //public void addCorsMappings(CorsRegistry registry) ;
    ///** 这里配置视图解析器 **/
    //void configureViewResolvers(ViewResolverRegistry registry);
    ///** 配置内容裁决的一些选项 **/
    //void configureContentNegotiation(ContentNegotiationConfigurer configurer);
    ///** 视图跳转控制器 **/
    //void addViewControllers(ViewControllerRegistry registry);
    ///** 静态资源处理 **/
    //void addResourceHandlers(ResourceHandlerRegistry registry);
    ///** 默认静态资源处理器 **/
    //void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer);

    @Autowired
    private TimeInterceptor timeInterceptor;

    /** 添加拦截器 **/
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(timeInterceptor);
        super.addInterceptors(registry);
    }
}
